<?php
/**
 * wp-foundation extensions/post.php
 */

function str_replace_assoc($array,$string){
	$from_array = array();
	$to_array = array();
	foreach ($array as $k => $v){
		$from_array[] = $k;
        $to_array[] = $v;
    }
	return str_replace($from_array,$to_array,$string);
}

function foundation_custom_meta_info(){
	global $id, $post, $authordata, $options;
	foreach ($options as $value) { if (get_settings( $value['id'] ) === FALSE) { $$value['id'] = $value['std']; } else { $$value['id'] = get_settings( $value['id'] ); }}
	if($fd_post_meta == "Show"){
	?>
	<div class="entry-meta">	
	<?php
		$authorlink = get_author_link( false, $authordata->ID, $authordata->user_nicename );
		$authorname = get_the_author();
		$category = get_the_category();
		$postdate = get_the_time(get_option('date_format'));
		$postdatefull = get_the_time('Y-m-d\TH:i:sO');
		
		$replace = array(
			'%authorname%' => $authorname,
			'%authorlink%' => $authorlink,
			'%postdate%' => $postdate,
			'%category%' => $category[0]->cat_name,
			'%categorylink%' => 'category/' . $category[0]->category_nicename,
			'%postdatefull%' => $postdatefull,
			'%|%' => '<span class="meta-sep"> | </span>'
		);
		echo stripslashes(str_replace_assoc($replace,$fd_post_meta_format)); 
	?>
	<?php edit_post_link( __( 'Edit', 'foundation' ), "<span class=\"meta-sep\"> | </span><span class=\"edit-link\">", "</span>" ) ?>
	</div><!-- .entry-meta -->
	<?php }
}
add_action('foundation_custom_meta','foundation_custom_meta_info');


function foundation_custom_utility_info(){
	global $id, $post, $authordata, $options;
	foreach ($options as $value) { if (get_settings( $value['id'] ) === FALSE) { $$value['id'] = $value['std']; } else { $$value['id'] = get_settings( $value['id'] ); }}
	if($fd_post_utility == "Show"){
	
	$category = get_the_category();
	$tags = get_the_tag_list('<ul><li>','</li><li>','</li></ul>');
	$commentcount = get_comments_number();
	$commentslink = get_comments_link();
	
	$replace = array(
			'%category%' => $category[0]->cat_name,
			'%categorylink%' => 'category/' . $category[0]->category_nicename,
			'%tags%' => $tags,
			'%commentcount%' => $commentcount,
			'%commentslink%' => $commentslink,
			'%|%' => '<span class="meta-sep"> | </span>'
		);
	
	?>
	<footer class="entry-utility">
	<?php
		echo stripslashes(str_replace_assoc($replace,$fd_post_utility_format));
		//edit_post_link( __( 'Edit', 'foundation' ), "<span class=\"meta-sep\">|</span><span class=\"edit-link\">", "</span>" ) 
	?>
	</footer><!-- #entry-utility -->
	<?php }
}
add_action('foundation_custom_utility','foundation_custom_utility_info');
?>